package com.zoranjoka.chordis.entities;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.apache.tapestry5.beaneditor.NonVisual;

@Entity(name="ALBUM")
public class AlbumBean implements Album{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@NonVisual
	private long id;
	@Basic
	private String name;
	@Basic
	private int year;
	@ManyToOne(targetEntity=ArtistBean.class)
	@JoinColumn(name="artist_ID")
	private Artist artist;
	@OneToMany(cascade=CascadeType.ALL, mappedBy="album")
	private List<SongBean> songs = new ArrayList<SongBean>();
	


	public AlbumBean(){}
	
	public AlbumBean(String name, int year, Artist artist) {
		super();
		this.name = name;
		this.year = year;
		this.artist = artist;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public Artist getArtist() {
		return artist;
	}
	public void setArtist(Artist a) {
		this.artist = a;
	}

	public List<SongBean> getSongs() {
		return songs;
	}

	public void setSongs(List<SongBean> songs) {
		this.songs = songs;
	}
	
	public void addSong(SongBean s)
	{
		this.songs.add(s);
	}
	
	public void deleteSong(SongBean s)
	{
		this.songs.remove(s);
	}

}
